<template>
  <yt-page title="作业详情"
    scroll>
    <yt-form>
      <yt-card title="票证信息">
        <yt-cell label="作业票证号"
          :value="item.ticket_number"></yt-cell>
        <yt-cell label="申请单位"
          :value="item.req_departName"></yt-cell>
        <yt-cell label="申请部门"
          :value="item.department_name"></yt-cell>
        <yt-cell label="作业类别"
          labelWidth="120px"
          :value="item.work_type"></yt-cell>
        <yt-cell label="申请日期"
          labelWidth="120px"
          :value="item.req_date"></yt-cell>
        <yt-cell label="作业开始时间"
          labelWidth="120px"
          :value="item.start_time"></yt-cell>
        <yt-cell border="none"
          label="作业结束时间"
          labelWidth="120px"
          :value="item.end_time"></yt-cell>
      </yt-card>
      <yt-card title="人员信息">
        <yt-cell label="作业负责人"
          :value="item.work_principal"></yt-cell>
        <yt-cell label="作业负责人电话"
          labelWidth="120px"
          :value="item.principal_tel"></yt-cell>
        <yt-cell label="作业监护人"
          labelWidth="120px"
          :value="item.work_guardian"></yt-cell>
        <yt-cell border="none"
          label="作业监护人电话"
          labelWidth="120px"
          :value="item.guardian_tel"></yt-cell>
      </yt-card>
      <yt-card title="上传照片">
        <yt-file :uploadFile="uploadFile"
          v-if="item.ticket_file"
          v-model="item.ticket_file"></yt-file>
      </yt-card>
      <yt-card title="上传视频">
        <yt-file :uploadFile="uploadFile"
          v-if="item.ticket_file"
          v-model="item.ticket_vedio"></yt-file>
      </yt-card>
      <yt-btn slot="btn"
        class="btn"
        theme="blue"
        edge
        @click="onSubmit">保存</yt-btn>
    </yt-form>
  </yt-page>
</template>

<script>
import { commonApi } from '@/common/api/commonApi.js'
import { ReplaceDictionary } from '@/common/utils/index.js'
export default {
  data() {
    return {
      form: {
        ticket_file: []
      },
      item: {},
      fileList: [],
      uploadFile: (file) => commonApi.uploadFile(file).then(({ _name, _url }) => ({ name: _name, url: _url }))
    }
  },
  activated() {
    this.getData()
  },
  methods: {
    async getData() {
      let p = [
        commonApi.searchById('spe_tickets_manager', this.$route.query.objectId),
        commonApi.dictionary('work_type'),
        commonApi.search('ent_enterprise')
      ]
      let [item, workTypeDic, entList] = await Promise.all(p)
      item.ticket_file = item.ticket_file ? item.ticket_file : []
      item.ticket_vedio = item.ticket_vedio ? item.ticket_vedio : []
      this.item = ReplaceDictionary(item, {
        work_type: workTypeDic,
        "req_departName:EnterpriseName:id": entList
      })
    },
    onSubmit() {
      commonApi.save('spe_tickets_manager', { ticket_file: this.item.ticket_file, ticket_vedio: this.item.ticket_vedio, objectId: this.item.id })
        .then(() => {
          this.$Toast('操作成功！', 'success')
        })
        .catch(() => {
          this.$Toast('操作失败！', 'error')
        })
    }
  }
}
</script>

<style scoped lang="stylus" rel="stylesheet/stylus" type="text/stylus">
>>>.flex {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}

>>>.flex {
  img {
    max-height: 60px;
    margin-bottom: 10px;
  }
}
</style>
